template< typename T >
struct rapidJSONHelper
{
    static const T getData( const rapidjson::Value& json , const std::string& name ){
        static_assert( !std::is_same<T , T >::value , "未支持的类型，请特化rapidJSONHelper" );
        return {};
    }
};

template<>
struct rapidJSONHelper< bool >
{
    static bool getData( const rapidjson::Value& json , const std::string& name ){
        if( json.HasMember( name.c_str() ) == false ){
            throw std::runtime_error( "字段不存在" );
        }   

        bool data = json[ name.c_str() ].GetBool();
        return data;
    }
};

template<>
struct rapidJSONHelper< char >
{
    static char getData( const rapidjson::Value& json , const std::string& name ){
        if( json.HasMember( name.c_str() ) == false ){
            throw std::runtime_error( "字段不存在" );
        }   

        char data = json[ name.c_str() ].GetInt();
        return data;
    }
};

template<>
struct rapidJSONHelper< short >
{
    static short getData( const rapidjson::Value& json , const std::string& name ){
        if( json.HasMember( name.c_str() ) == false ){
            throw std::runtime_error( "字段不存在" );
        }   

        short data = json[ name.c_str() ].GetInt();
        return data;
    }
};

template<>
struct rapidJSONHelper< int >
{
    static int getData( const rapidjson::Value& json , const std::string& name ){
        if( json.HasMember( name.c_str() ) == false ){
            throw std::runtime_error( "字段不存在" );
        }   

        int data = json[ name.c_str() ].GetInt();
        return data;
    }
};

template<>
struct rapidJSONHelper< long >
{
    static long getData( const rapidjson::Value& json , const std::string& name ){
        if( json.HasMember( name.c_str() ) == false ){
            throw std::runtime_error( "字段不存在" );
        }   

        long data = (long)json[ name.c_str() ].GetInt64();
        return data;
    }
};

template<>
struct rapidJSONHelper< long long >
{
    static long long getData( const rapidjson::Value& json  , const std::string& name ){
        if( json.HasMember( name.c_str() ) == false ){
            throw std::runtime_error( "字段不存在" );
        }   

        long long data = json[ name.c_str() ].GetInt64();
        return data;
    }
};

template<>
struct rapidJSONHelper< uint8_t >
{
    static uint8_t getData( const rapidjson::Value& json , const std::string& name ){
        if( json.HasMember( name.c_str() ) == false ){
            throw std::runtime_error( "字段不存在" );
        }   

        uint8_t data = json[ name.c_str() ].GetUint();
        return data;
    }
};

template<>
struct rapidJSONHelper< uint16_t >
{
    static uint16_t getData( const rapidjson::Value& json ,  const std::string& name ){
        if( json.HasMember( name.c_str() ) == false ){
            throw std::runtime_error( "字段不存在" );
        }   

        uint16_t data = json[ name.c_str() ].GetUint();
        return data;
    }
};

template<>
struct rapidJSONHelper< uint32_t >
{
    static uint32_t getData( const rapidjson::Value& json , const std::string& name ){
        if( json.HasMember( name.c_str() ) == false ){
            throw std::runtime_error( "字段不存在" );
        }   

        uint32_t data = json[ name.c_str() ].GetUint();
        return data;
    }
};

template<>
struct rapidJSONHelper< uint64_t >
{
    static uint64_t getData( const rapidjson::Value& json , const std::string& name ){
        if( json.HasMember( name.c_str() ) == false ){
            throw std::runtime_error( "字段不存在" );
        }   

        uint64_t data = json[ name.c_str() ].GetUint64();
        return data;
    }
};

template<>
struct rapidJSONHelper< float >
{
    static float getData( const rapidjson::Value& json , const std::string& name ){
        if( json.HasMember( name.c_str() ) == false ){
            throw std::runtime_error( "字段不存在" );
        }   

        float data = json[ name.c_str() ].GetFloat();
        return data;
    }
};

template<>
struct rapidJSONHelper< double >
{
    static double getData( const rapidjson::Value& json , const std::string& name ){
        if( json.HasMember( name.c_str() ) == false ){
            throw std::runtime_error( "字段不存在" );
        }   

        double data = json[ name.c_str() ].GetDouble();
        return data;
    }
};

template<>
struct rapidJSONHelper< std::string >
{
    static std::string getData( const rapidjson::Value& json ,  const std::string& name ){
        if( json.HasMember( name.c_str() ) == false ){
            MSG_1( "JSON字段不存在： %s" , TRED , name.c_str() );
            wheels::debug::printCallstack();
            throw std::runtime_error( "字段不存在" );
        }   
        std::string data;
        const char * d = json[ name.c_str() ].GetString();
        if( d == nullptr ){
            MSG_1( "JSON字段内容不存在： %s" , TRED , name.c_str() );
        }else{
            data = d;
        }

        return data;
    }
};